$(document).ready(function(){
    getsalelist();
    mui.init({
        pullRefresh: {
            container: '#pullrefresh',
            down: {
                callback: pulldownRefresh
            },
            up: {
                contentrefresh: '...',
                callback: pullupRefresh
            }
        }
    });
})

function pulldownRefresh() {
    mui('#pullrefresh').pullRefresh().endPulldownToRefresh(); 
}
/**
 * 上拉加载具体业务实现
 */
function pullupRefresh() {
    mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
}

function getsalelist(){
    var params = {};
    mzpost({
        url:pub_stock_list,
        data:params,
        success:function(res){
            if(res.code == '2000'){
               var data = res.data;
               
               createList(data);
               
            }else{
                mui.toast(res.msg);
            }
        },
        error:function(err){
            
            mui.toast('获取商品库存错误');
        }
    })
}


function createList(data){
    $.each(data,function(i,item){
        var stockimg = item.stock_num < 5 ? '/imgs/pub/saleout.png' : '/imgs/pub/notout.png';
        var reminder = item.stock_num < 5 ? '<span style="margin-left:0.3rem;color:red;">请及时补充库存</span>' : '';
        $('#title').after(' <div class="mui-content">'+
        ' <div class="mui-row">'+
           ' <div class="mui-col-xs-4 cell imgcell">'+
            '<div>'+
                ' <img src="'+item.img+'" alt="">'+
                    '</div>'+
                ' </div>'+
            ' <div class="mui-col-xs-8 cell subcell">'+
            '<div class="mui-col-xs-12">'+item.name+' <img src="'+stockimg+'"></div>'+
                '<div class="mui-col-xs-12">'+
                '<span>销量：'+item.sale_num+'</span>'+
                '<span style="margin-left:0.3rem;">库存：'+item.stock_num+'</span>'+reminder+
                '</div>'+
                '</div>'+
       '</div>'+
       '</div> ');
    })
}